package com.study.completable;

import java.util.concurrent.CompletableFuture;

/**
 * @author wanghao
 * @version v1.0
 * @description: 异步调用和同步调用
 * @date 2022/1/5 18:10
 * @change [修改时间] [修改者]@[版本号] [修改内容说明]
 */
public class CompletableFutureDemo {

    public static void main(String[] args) throws Exception {
        // 同步调用
        CompletableFuture<Void> completableFuture1 = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + ": CompletableFuture1");
        });
        completableFuture1.get();

        // 异步调用
        CompletableFuture<Integer> completableFuture2 = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + " : CompletableFuture2");
            return 1024;
        });
        completableFuture2.whenComplete((t,u)->{
            System.out.println("---------t="+t);
            System.out.println("---------u="+u);
        }).get();

    }

}
